#include "audiorecorder.hxx"

#include "myfilelog.hxx"
#include "loghelper.hxx"

AudioRecorder::AudioRecorder()
:	Thread(),_bits_per_sample(0),_samples_per_sec(0),
	_block_nb(0),_block_size(0),_current_block(0),_free_block_count(_block_nb),
	_channel_nb(0),_mutex_on_count(),_mutex_on_resource(),_filelog(NULL)
{}
AudioRecorder::AudioRecorder(tUInt32 bits_sample,tUInt32 sample_sec,tUInt32 block_nb,tUInt32 block_size,tUInt32 channel_nb,FileLog* filelog)
:	Thread(),_bits_per_sample(bits_sample),_samples_per_sec(sample_sec),
	_block_nb(block_nb),_block_size(block_size),_current_block(0),_free_block_count(_block_nb),
	_channel_nb(channel_nb),_mutex_on_count(),_mutex_on_resource(),_filelog(filelog)
{}
AudioRecorder::~AudioRecorder()
{}
tInt32 AudioRecorder::IncrFreeBlockCount(void)
{
	tUInt32 ret = 0;

	_mutex_on_count.Lock();

	if (_free_block_count < _block_nb)
	{
		_free_block_count++;
	}

	ret = _free_block_count;

	_mutex_on_count.Unlock();

	return ret;
}
tInt32 AudioRecorder::DecrFreeBlockCount(void)
{
	tUInt32 ret = 0;

	_mutex_on_count.Lock();
	
	if (_free_block_count>0)
		ret = --_free_block_count;
	else
		ret = -1;

	_mutex_on_count.Unlock();

	return ret;
}